//
//  ConnectListCell.m
//  QiFuLianMeng
//
//  Created by yuntai on 2017/4/24.
//  Copyright © 2017年 yuntai. All rights reserved.
//

#import "ConnectListCell.h"

@implementation ConnectListCell

- (void)awakeFromNib {
    [super awakeFromNib];

    self.countLabel.layer.cornerRadius =  self.countLabel.frame.size.width/2.0;
    self.countLabel.layer.masksToBounds = YES;
    
    self.headIV.layer.cornerRadius = 5.f;
    self.headIV.layer.masksToBounds =YES;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (void)configcellWithModel:(ChatRecent *)model index:(NSIndexPath *)indexPath{
    
        self.timelabel.hidden = NO;
        self.detailLabel.hidden = NO;
        self.countLabel.text = [[NSNumber numberWithInteger: model.unReadCount] stringValue];
        NSDictionary *dic = [ChatContactMgr fetchContactMemNameByContactId:model.ContactId];
        self.nameLabel.text = [dic objectForKey:@"userName"]?:model.ContactName?:model.ContactId;
//        self.nameLabel.text = model.ContactName?:model.ContactId;
    
    [self.headIV sd_setImageWithURL:[NSURL URLWithString:[dic objectForKey:@"headPath"]] placeholderImage:[UIImage imageNamed:@"wode"]];
    
    model.ContactName = [dic objectForKey:@"userName"]?:@" ";
    
    self.timelabel.text = [NSString stringPreviousTime:[NSString stringFromNSDate:[NSDate  date]]
                                                withLatterTime:model.createTime];
    NSString *strrr =[self setmessagestr:model.messageBody];
    self.detailLabel.text = strrr;
    
    if (self.countLabel.text == nil || [self.countLabel.text isEqualToString:@"0"] ||[self.countLabel.text isEqualToString:@""]) {
        self.countLabel.hidden = YES;
    }else{
        self.countLabel.hidden = NO;
    }
}
- (NSString *)setmessagestr:(NSString *)contentString
{
    if (contentString.length == 0) {
        return @"";
    }
    self.tempstr = contentString;
    NSString* pattern = @"<[1-9][0-9]?.gif>";
    
    NSRegularExpression* regx = [[NSRegularExpression alloc] initWithPattern:pattern options:NSRegularExpressionCaseInsensitive error:nil];
    [regx enumerateMatchesInString:self.tempstr options:NSMatchingReportProgress range:NSMakeRange(0, self.tempstr.length) usingBlock:^(NSTextCheckingResult * _Nullable result, NSMatchingFlags flags, BOOL * _Nonnull stop) {
        NSString* resultString = [self.tempstr substringWithRange:result.range];
        if (resultString.length == 7) {
            self.tempstr = [self.tempstr stringByReplacingOccurrencesOfString:resultString withString:@"[ 表 情 ]"];
        }else{
            self.tempstr = [self.tempstr stringByReplacingOccurrencesOfString:resultString withString:@"[ 表  情 ]"];
        }
       

    }];
    self.tempstr = [self.tempstr stringByReplacingOccurrencesOfString:@" " withString:@""];
    return self.tempstr;
    
}

@end
